{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {},
  "cells": [
    {
      "metadata": {},
      "source": [
        "<td>\n",
        "   <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n",
        "</td>"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "<td>\n",
        "<a href=\"https://colab.research.google.com/github/Labelbox/labelbox-python/blob/master/examples/basics/datasets.ipynb\" target=\"_blank\"><img\n",
        "src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>\n",
        "</td>\n",
        "\n",
        "<td>\n",
        "<a href=\"https://github.com/Labelbox/labelbox-python/tree/master/examples/basics/datasets.ipynb\" target=\"_blank\"><img\n",
        "src=\"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\"GitHub\"></a>\n",
        "</td>"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "# Datasets"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "* Datasets are collections of data rows (image, video, or text to be labeled)\n",
        "* Datasets are used to define units of work.\n",
        "    * Attaching a dataset to a project will add all data rows in the dataset to the project (and add them to the queue)\n",
        "* Datasets are not required to be fixed in size (you can add data rows at any time). \n",
        "    * However, if you add data rows to a dataset, all projects associated with this dataset will add the new data rows to its queue"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "!pip install labelbox"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "import labelbox as lb\n",
        "import uuid\n",
        "import os"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "* Set the following cell with your data to run this notebook"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "# Pick a dataset that has attached data_rows\n",
        "DATASET_ID = \"ckm4xyfua04cf0z7a3wz58kgj\""
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "# API Key and Client\n",
        "Provide a valid api key below in order to properly connect to the Labelbox Client."
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "# Add your api key\n",
        "API_KEY = None\n",
        "client = lb.Client(api_key=API_KEY)"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "### Read"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "# Can be fetched by name (using a query - see basics), or using an id directly\n",
        "dataset = client.get_dataset(DATASET_ID)"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "print(dataset)"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "# We can see the data rows associated with a dataset\n",
        "data_rows = dataset.data_rows()\n",
        "next(data_rows)  # Print first data row"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "### Create"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "new_dataset = client.create_dataset(name=\"my_new_dataset\")\n",
        "print(new_dataset)"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "* Add data rows\n",
        "* See the [data rows](https://colab.research.google.com/github/Labelbox/labelbox-python/blob/master/examples/basics/data_rows.ipynb#scrollTo=successful-patch) notebook `Create` section for more about adding data rows."
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "new_dataset.create_data_row(row_data=\"https://picsum.photos/200/300\")"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "### Update"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "new_dataset.update(name=\"new_name\")"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    },
    {
      "metadata": {},
      "source": [
        "### Delete"
      ],
      "cell_type": "markdown"
    },
    {
      "metadata": {},
      "source": [
        "new_dataset.delete()"
      ],
      "cell_type": "code",
      "outputs": [],
      "execution_count": null
    }
  ]
}